package com.http.demo;

import java.util.Map;

import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;

/**
 * 2017-5-17 爬取指定URL的图片
 * 
 * @author tom
 *
 */
public class HttpRequest {
    public static String HttpRequestGet(String url, String map,int outtime) throws Exception {
        //获取工具类返回的html,并用Jsoup解析
        Connection conn = Jsoup.connect(url).timeout(0);
    	conn.header("Content-Type", "application/json; charset=UTF-8");
        Response response;
        System.out.println(conn.ignoreContentType(true).method(Method.GET).request());
        response = conn.ignoreContentType(true).method(Method.GET).execute();
        return response.body();
        //获取所有的img元素
    }
    public static String HttpRequestPost(String url,String map,int outtime) throws Exception {
        //获取工具类返回的html,并用Jsoup解析
    	System.out.println(url);
        Connection conn = Jsoup.connect(url).timeout(0);
        conn.header("Request-Line", "POST /cgi-bin/login?lang=zh_CN HTTP/1.1");
		conn.header("Accept", "application/json, text/javascript, */*; q=0.01");
		conn.header("Accept-Encoding", "gzip, deflate");
		conn.header("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6");
		conn.header("Cache-Control", "no-cache");
		conn.header("Connection", "Keep-Alive");
		conn.header("Content-Type", "application/json; charset=UTF-8");
		conn.header("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; MALC)");
        Response response;
        response = conn.ignoreContentType(true).method(Method.POST).data(map).execute();
        return response.body();
        //获取所有的img元素
    }
}
